package ace.module.tenant.core.impl.controller.rest.admin.ext;

import ace.cmp.core.model.R;
import ace.cmp.security.oauth2.resource.server.core.annotation.PreAuthorizeIsUserAuthenticated;
import ace.module.account.api.model.dto.IamApplicationDto;
import ace.module.tenant.core.impl.service.TenantService;
import ace.module.upms.api.model.dto.UpmsApplicationDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 租户 admin controller.
 *
 * @author caspar
 */
@Tag(name = "租户-管理-API")
@PreAuthorizeIsUserAuthenticated
@AllArgsConstructor
@RestController
@RequestMapping(TenTenantExtAdminController.PATH)
@Valid
public class TenTenantExtAdminController {

  public static final String PATH = "/tenant/admin/tenant/v1";
  private static final String URI_GET_TENANT_IAM_APP = "/getTenantIamApp";
  public static final String URL_GET_TENANT_IAM_APP = PATH + URI_GET_TENANT_IAM_APP;
  private static final String URI_GET_TENANT_UPMS_APP = "/getTenantUpmsApp";
  public static final String URL_GET_TENANT_UPMS_APP = PATH + URI_GET_TENANT_UPMS_APP;

  private final TenantService tenantService;

  @Operation(summary = "查询租户账户应用", description = "")
  @PostMapping(URI_GET_TENANT_IAM_APP)
  public R<IamApplicationDto> getTenantIamApp(@RequestParam("tenantId") Long tenantId) {
    IamApplicationDto result = tenantService.getTenantIamAppByTenantId(tenantId);
    return R.ok(result);
  }

  @Operation(summary = "查询租户权限应用", description = "")
  @PostMapping(URI_GET_TENANT_UPMS_APP)
  public R<UpmsApplicationDto> getTenantUpmsApp(@RequestParam("tenantId") Long tenantId) {
    UpmsApplicationDto result = tenantService.getTenantUpmsAppByTenantId(tenantId);
    return R.ok(result);
  }
}
